package com.cyzy.service.impl;

import com.cyzy.service.FareStrategy;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author cuncun
 * @create 2025-05-28 下午8:17
 *
 *  根据当前时间判断使用的是哪种计价规则
 */

@Service
public class FareStrategyContext {

//    存储map true对应着白天   false对应着黑夜   ConcurrentHashMap<>()适用于高并发 更安全
    private final Map<Boolean, FareStrategy> strategyMap = new ConcurrentHashMap<>();

    public FareStrategyContext(DayFareStrategy dayFareStrategy, NightFareStrategy nightFareStrategy){
        strategyMap.put(Boolean.FALSE,dayFareStrategy);
        strategyMap.put(Boolean.TRUE,nightFareStrategy);
    }

    //根据传入的key值判断是白天黑夜
    public FareStrategy getFareStrategy(boolean isNi){
        return strategyMap.get(isNi);
    }
}
